package com.zzw.controller;

import com.zzw.entity.Result;
import com.zzw.entity.Store;
import com.zzw.page.Page;
import com.zzw.service.StoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Project: warehouse
 * @Description:
 * @Author: zzw
 */
@RestController
@RequestMapping("/store")
@Slf4j
@Api(tags = "仓库模块")
public class StoreController {

    @Autowired
    private StoreService storeService;

    /**
     * 查询所有仓库的url接口
     *
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查询所有仓库")
    public Result storeList() {
        List<Store> storeList = storeService.queryAllStore();
        return Result.ok(storeList);
    }

    /**
     * 分页查询仓库的url接口
     *
     * @param page
     * @param store
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询仓库")
    public Result storePageList(Page page, Store store) {
        Page page1 = storeService.queryStorePage(page, store);
        return Result.ok(page1);
    }

    /**
     * 校验仓库编号是否存在的url接口
     *
     * @param storeNum
     * @return
     */
    @GetMapping("/{storeNum}")
    @ApiOperation("校验仓库编号")
    public Result checkStoreNum(@PathVariable String storeNum) {
        return storeService.checkStoreNum(storeNum);
    }

    /**
     * 添加仓库的url接口
     *
     * @param store
     * @return
     */
    @PostMapping
    @ApiOperation("添加仓库")
    public Result saveStore(@RequestBody Store store) {
        return storeService.saveStore(store);
    }

    /**
     * 修改仓库的url接口
     *
     * @param store
     * @return
     */
    @PutMapping
    @ApiOperation("修改仓库")
    public Result updateStore(@RequestBody Store store) {
        return storeService.updateStore(store);
    }

    /**
     * 删除仓库的url接口
     *
     * @param storeId
     * @return
     */
    @DeleteMapping("/{storeId}")
    @ApiOperation("删除仓库")
    public Result deleteStore(@PathVariable Integer storeId) {
        return storeService.deleteStore(storeId);
    }

    /**
     * 导出仓库数据的url接口
     *
     * @param page
     * @param store
     * @return
     */
    @GetMapping("/exportTable")
    @ApiOperation("导出数据")
    public Result exportTable(Page page, Store store) {
        //分页查询仓库
        Page page1 = storeService.queryStorePage(page, store);
        //拿到当前页数据
        List<?> resultList = page1.getResultList();
        return Result.ok(resultList);
    }
}
